﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web.Mvc;
using GuRenFang.Common;
using GuRenFang.Service.Entity;
using GuRenFang.Service.IBiz;

namespace GuRenFang.Controllers.WebSite
{
    [ErrorHanderFilter]
    public class CategoryController : Controller
    {
        private readonly IPictorialCategoryBiz _pictorialService;
        private readonly IWeddingCategoryBiz _weddingCategory;

        public CategoryController(IPictorialCategoryBiz pictorialService, IWeddingCategoryBiz weddingCategory)
        {
            _pictorialService = pictorialService;
            _weddingCategory = weddingCategory;
        }


        public ActionResult TopCategoryForHomePage()
        {
            int totalRecord = 0;
            IEnumerable<PictorialCategory> pictorialCategorys = _pictorialService.GetCategoryByPages(out totalRecord,
                                                                                                     pageIndex: 1,
                                                                                                     pageSize: 8,
                                                                                                     orderFiled: "");
            IEnumerable<WeddingCategory> weddingCategorys = _weddingCategory.GetCategoryByPages(out totalRecord,
                                                                                                pageIndex: 1,
                                                                                                pageSize: 8,
                                                                                                orderFiled: "");
            IList<CategoryModel> categoryModels = pictorialCategorys.Select(pictorialCategory => new CategoryModel()
                                                                                                     {
                                                                                                         CategoryType = 2, Id = pictorialCategory.Id, Name = pictorialCategory.Name, ThumbnailPath = pictorialCategory.ThumbnailPath
                                                                                                     }).ToList();

            foreach (var weddingCategory in weddingCategorys)
            {
                var model = new CategoryModel()
                {
                    CategoryType = 1,
                    Id = weddingCategory.Id,
                    Name = weddingCategory.Name,
                    ThumbnailPath = weddingCategory.ThumbnailPath
                };
                categoryModels.Add(model);
            }
            return PartialView("_HomePageScript", categoryModels);//SerializationHelper.SerializeToJson
        }
    }
}
